package com.jhgsys.internal.hazard.controller;

import com.jhgsys.internal.common.annotation.Log;
import com.jhgsys.internal.common.controller.BaseController;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.entity.FebsResponse;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.exception.FebsException;
import com.jhgsys.internal.common.utils.FebsUtil;
import com.jhgsys.internal.hazard.entity.HazardReportAreaUser;
import com.jhgsys.internal.hazard.service.IHazardReportAreaUserService;
import com.wuwenze.poi.ExcelKit;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
 *  Controller
 *
 * @author wanghw
 * @date 2024-09-18 14:27:18
 */
@Slf4j
@Validated
@Controller
public class HazardReportAreaUserController extends BaseController {

    @Autowired
    private IHazardReportAreaUserService hazardReportAreaUserService;

    @GetMapping(FebsConstant.VIEW_PREFIX + "hazardReportAreaUser")
    @RequiresPermissions("hazardReportAreaUser:view")
    public String hazardReportAreaUserIndex(){
        return jumpPage("hazard/hazardReportAreaUser/hazardReportAreaUserList");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "hazardReportAreaUser/add")
    @RequiresPermissions("hazardReportAreaUser:add")
    public String hazardReportAreaUserAdd(){
        return jumpPage("hazard/hazardReportAreaUser/hazardReportAreaUserEdit");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "hazardReportAreaUser/update/{id}")
    @RequiresPermissions("hazardReportAreaUser:edit")
    public String hazardReportAreaUserUpdate(Model model, @PathVariable("id") String id){
        model.addAttribute("hazardReportAreaUser", hazardReportAreaUserService.findHazardReportAreaUserById(id));
        return jumpPage("hazard/hazardReportAreaUser/hazardReportAreaUserEdit");
    }

    /**
     * 查询（所有）
     * @author wanghw
     * @date 2024-09-18 14:27:18
     */
    @GetMapping("hazardReportAreaUser")
    @ResponseBody
    @RequiresPermissions("hazardReportAreaUser:view")
    public FebsResponse getAllHazardReportAreaUsers(HazardReportAreaUser hazardReportAreaUser) {
        try {
            return success(hazardReportAreaUserService.findHazardReportAreaUserList(hazardReportAreaUser));
        }catch (Exception ex){
            return failure(ex);
        }

    }

    /**
     * 查询（分页）
     * @author wanghw
     * @date 2024-09-18 14:27:18
     */
    @GetMapping("hazardReportAreaUser/list")
    @ResponseBody
    @RequiresPermissions("hazardReportAreaUser:view")
    public FebsResponse hazardReportAreaUserList(QueryRequest request, HazardReportAreaUser hazardReportAreaUser) {
        try {
            Map<String, Object> dataTable = getDataTable(this.hazardReportAreaUserService.findHazardReportAreaUserPage(request, hazardReportAreaUser));
            return success(dataTable);
        }catch (Exception ex){
            return failure(ex);
        }
    }

    /**
     * 新增 HazardReportAreaUser
     * @author wanghw
     * @date 2024-09-18 14:27:18
     */
    @Log("新增HazardReportAreaUser")
    @PostMapping("hazardReportAreaUser")
    @ResponseBody
    @RequiresPermissions("hazardReportAreaUser:add")
    public FebsResponse addHazardReportAreaUser(@Valid HazardReportAreaUser hazardReportAreaUser) throws FebsException {
        try {
            this.hazardReportAreaUserService.createHazardReportAreaUser(hazardReportAreaUser);
            return success();
        } catch (Exception ex) {
            return failure(ex,"新增失败");
        }
    }

    /**
     * 逻辑删除 HazardReportAreaUser
     * @author wanghw
     * @date 2024-09-18 14:27:18
     */
    @Log("逻辑删除HazardReportAreaUser")
    @GetMapping("hazardReportAreaUser/delete/{id}")
    @ResponseBody
    @RequiresPermissions("hazardReportAreaUser:delete")
    public FebsResponse deleteHazardReportAreaUser(@PathVariable("id") String hazardReportAreaUserIds) throws FebsException {
        try {
            HazardReportAreaUser hazardReportAreaUser = new HazardReportAreaUser();
            this.hazardReportAreaUserService.deleteHazardReportAreaUser(hazardReportAreaUser,hazardReportAreaUserIds);
            return success();
        } catch (Exception ex) {
            return failure(ex,"删除失败");
        }
    }

    /**
    * 物理删除 HazardReportAreaUser
    * @author wanghw
    * @date 2024-09-18 14:27:18
    */
    @Log("物理删除HazardReportAreaUser")
    @GetMapping("hazardReportAreaUser/physicallyDelete/{id}")
    @ResponseBody
    @RequiresPermissions("hazardReportAreaUser:delete")
    public FebsResponse physicallyDeleteHazardReportAreaUser(@PathVariable("id") String hazardReportAreaUserIds) throws FebsException {
        try {
            this.hazardReportAreaUserService.physicallyDeleteHazardReportAreaUser(hazardReportAreaUserIds);
            return success();
        } catch (Exception ex) {
            return failure(ex,"删除失败");
        }
    }

    /**
     * 修改 HazardReportAreaUser
     * @author wanghw
     * @date 2024-09-18 14:27:18
     */
    @Log("修改HazardReportAreaUser")
    @PostMapping("hazardReportAreaUser/update")
    @ResponseBody
    @RequiresPermissions("hazardReportAreaUser:edit")
    public FebsResponse updateHazardReportAreaUser(HazardReportAreaUser hazardReportAreaUser) throws FebsException {
        try {
            this.hazardReportAreaUserService.updateHazardReportAreaUser(hazardReportAreaUser);
            return success();
        } catch (Exception ex) {
            return failure(ex,"修改失败");
        }
    }

}
